package top.tagao.m03_beHavioralPatterns.b_13chain;

import top.tagao.m03_beHavioralPatterns.b_13chain.middleware.MiddleWare;
import top.tagao.m03_beHavioralPatterns.b_13chain.middleware.RoleCheckMiddleWare;
import top.tagao.m03_beHavioralPatterns.b_13chain.middleware.ThrottlingMiddleware;
import top.tagao.m03_beHavioralPatterns.b_13chain.middleware.UserExistsMiddleWare;
import top.tagao.m03_beHavioralPatterns.b_13chain.server.Server;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * 责任链模式
 */
public class Main {

    private static Server server;


    private static void init() {
        server = new Server();
        server.register("admin@example.com", "admin_pass");
        server.register("user@example.com", "user_pass");

        // All checks are linked. Client can build various chains using the same
        // components.
        MiddleWare middleware = MiddleWare.link(
                new ThrottlingMiddleware(2),
                new UserExistsMiddleWare(server),
                new RoleCheckMiddleWare()
        );

        // Server gets a chain from client code.
        server.setMiddleware(middleware);
    }

    public static void main(String[] args) {
        init();
        String email = "admin@example.com";
        String password =  "admin1_pass";
        server.logIn(email, password);

    }
}
